package com.finalab.yueqiu.entity.user;


import com.qcloud.cos.utils.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * @author 莉安
 */
public class User {
    private Integer id;
    @Length(min = PHONE_LENGTH, max = PHONE_LENGTH)
    private String phone;
    @Length(min = PASSWORD_MIN, max = PASSWORD_MAX)
    private String password;
    private String salt;


    private static final int PHONE_LENGTH = 11;
    private static final int PASSWORD_MIN = 8;
    private static final int PASSWORD_MAX = 20;
    public User() {
    }

    public boolean registerValid(int phoneLength , int passwordMin, int passwordMax){
        if(com.qcloud.cos.utils.StringUtils.isNullOrEmpty(phone) || StringUtils.isNullOrEmpty(password)){
            return false;
        }
        if(password.length() < passwordMin || password.length() > passwordMax){
            return false;
        }
        if(phone.length() != phoneLength ){
            return false;
        }
        return true;
    }


    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", phone='" + phone + '\'' +
                ", password='" + password + '\'' +
                ", salt='" + salt + '\'' +
                '}';
    }
}
